<?php include 'header.php'; ?>
<script>
    $(document).ready(function() {

        //if submit button is clicked
        $('#submit').click(function() {

            var data = 'hotelId=<?php echo($_GET["hotelId"]); ?>' + '&roomTypeCode=<?php echo($_GET["roomTypeCode"]); ?>' + '&smokingYN=<?php echo($_GET["smokingYN"]); ?>' + '&outdate=<?php echo($_GET["outdate"]); ?>' + '&indate=<?php echo($_GET["indate"]); ?>';

            $('.text').attr('disabled', 'true');

            //start the ajax
            $.ajax({
                url: "db/RoomReservation.php",
                type: "POST",
                dataType: "xml",
                //pass the data			
                data: data,
                //Do not cache the page
                cache: false,
                //success
                success: function(xml) {
                    if (data = $('result', xml).text().replace(/(\r\n|\n|\r)/g, "<br />")) {
                        $("#confirm").html("Your room has been reserved.");
                        
                    }
                    else {
                        
                        $(xml).find('error').each(function() {
                            data += $(this).text()+'<br>';
                           
                        });
                       
                        $("#modal-body").html(data);
                        $("#errormodal").modal('show')
                    }
                }
            });

            //cancel the submit button default behaviours
            return false;
        });
    });
</script>
<h1>Confirm Reservation</h1>


<?php if (empty($_SESSION['customerId'])) {
    echo "You must be logged in to reserve a room.  <a href='register.php'>Click here</a> to register or sign in to proceed.";
    include 'footer.php';
    exit();
}
?>
<div class="well" id="confirm">
<p><b>Destination:</b> <?php echo($_GET['hotelName']); ?></p>
<p><b>Room Type:</b> <?php echo($_GET['roomTypeDescription']); ?></p>
<p><b>Smoking:</b> <?php echo($_GET['smokingYN']); ?></p>
<p><b>Check In:</b> <?php echo($_GET['indate']); ?></p>
<p><b>Check Out:</b> <?php echo($_GET['outdate']); ?></p>
<p><b>Daily Room Rate:</b> <?php echo($_GET['roomRate']); ?></p>
<button type="submit" id="submit" class="btn btn-primary btn-medium">Reserve Room</button>
</div>

<div id="errormodal" class="modal hide fade" style="display: none; z-index: 20000000000;">
    <div class="modal-header">
        <button class="close" data-dismiss="modal">×</button>
        <h3>Reservation Error</h3>
    </div>
    <div class="modal-body" id="modal-body">

    </div>
</div>

<?php include 'footer.php'; ?>